package com.step.sprite.animation;

import com.step.Step;


public class AnimationMd2 extends Animation{
	float[] interPolatedVerts;
	float[] interPolatedNormals;
	KeyFrameMd2 curFrame;
	
	public AnimationMd2(KeyFrameMd2... frames) {
		super(frames);
		this.curFrame = (KeyFrameMd2)currentFrame;		
	}
	
	public void update(){
		super.update();
		Step.log("AnimationMd2-更新动画");
		curFrame = (KeyFrameMd2)currentFrame;
		KeyFrameMd2 nextFrame = (KeyFrameMd2)frames.get((currentFrameIndex + 1) % numFrames);
		float[] currentVerts = curFrame.getVertices();
		float[] nextVerts = nextFrame.getVertices();
		float[] currentNormals = curFrame.getNormals();
		float[] nextNormals = nextFrame.getNormals();
		int numVerts = currentVerts.length;
		
		this.interPolatedVerts = new float[curFrame.getVertices().length];
		this.interPolatedNormals = new float[curFrame.getNormals().length];
		
		for (int i = 0; i < numVerts; i += 3) {
			interPolatedVerts[i] = currentVerts[i] + interpolation * (nextVerts[i] - currentVerts[i]);
			interPolatedVerts[i + 1] = currentVerts[i + 1] + interpolation * (nextVerts[i + 1] - currentVerts[i + 1]);
			interPolatedVerts[i + 2] = currentVerts[i + 2] + interpolation 	* (nextVerts[i + 2] - currentVerts[i + 2]);
			interPolatedNormals[i] = currentNormals[i] + interpolation * (nextNormals[i] - currentNormals[i]);
			interPolatedNormals[i + 1] = currentNormals[i + 1] + interpolation * (nextNormals[i + 1] - currentNormals[i + 1]);
			interPolatedNormals[i + 2] = currentNormals[i + 2] + interpolation * (nextNormals[i + 2] - currentNormals[i + 2]);			
		}
	}
	
	public float[] getVertices(){
		return interPolatedVerts;
	}
	
	public float[] getNormals(){
		return interPolatedNormals;
	}
}
